package Classification.DecisionTree;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataSet {
	double size;
	String[] Headers;
	List<DataRow> rows;
	Map<String, Integer>[] ValueCount;
	
	
	public DataSet(String filename, String separator) throws IOException
	{
		BufferedReader file = new BufferedReader(new FileReader(filename));
		Headers = file.readLine().split(separator);
		
		String currentLine;
		rows = new ArrayList<DataRow>();
		ValueCount = (HashMap<String, Integer>[]) new HashMap[Headers.length];
		for (int i = 0; i < Headers.length; i++)
		{
			ValueCount[i] = new HashMap<String, Integer>();
		}
		while ((currentLine = file.readLine()) != null)
		{
			String[] vals = currentLine.split(separator);
			rows.add(new DataRow(vals));
			
			for (int i = 0; i < vals.length; i++)
			{
				if (ValueCount[i].containsKey(vals[i]))
					ValueCount[i].put(vals[i], ValueCount[i].get(vals[i])+1);
				else
					ValueCount[i].put(vals[i], 1);
			}
		}
		
		size = rows.size();
	}
	
	public int LocationOfAttribute(String attribute)
	{
		for (int i = 0; i < Headers.length; i++)
			if (Headers[i].equals(attribute))
				return i;
		
		return -1;
	}
	
	private void printVals()
	{
		for (DataRow node : rows)
		{
			for (String val : node.values)
			{
				System.out.print(val + " ");
			}
			System.out.println();
		}
	}
}
